package br.com.automed.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="CM_CARGO")
@NamedQueries({
	@NamedQuery(name="listarCargo", query="FROM Cargo c"),
	@NamedQuery(name="listarCargoByTipo", query="FROM Cargo c WHERE c.cargo = :cargo"),
	@NamedQuery(name="listarCargoFuncionarios", query="FROM Cargo c WHERE c.cargo <> :param1 AND c.cargo <> :param2")
})
public class Cargo {
	
	public static final String NAMED_QUERY_LIST_CARGO 				= "listarCargo";
	public static final String NAMED_QUERY_LIST_CARGO_BY_TIPO 		= "listarCargoByTipo";
	public static final String NAMED_QUERY_LIST_CARGO_FUNCIONARIOS 	= "listarCargoFuncionarios";
	
	@Id
    @GeneratedValue(generator = "system-uuid", strategy=GenerationType.AUTO)
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "ID_CARGO")
	private String idCargo;

	@Column(name = "ST_CARGO")
	private String cargo;
	
	@OneToMany(mappedBy="cargo")
	private List<Funcionario> funcionarios;
	
	public Cargo() {
		// TODO Auto-generated constructor stub
	}
	
	public Cargo(String idCargo, String cargo) {
		this.idCargo = idCargo;
		this.cargo = cargo;
	}

	public String getIdCargo() {
		return idCargo;
	}
	public void setIdCargo(String idCargo) {
		this.idCargo = idCargo;
	}
	public String getCargo() {
		return cargo;
	}
	public void setCargo(String cargo) {
		this.cargo = cargo;
	}
	public List<Funcionario> getFuncionarios() {
		return funcionarios;
	}
	public void setFuncionarios(List<Funcionario> funcionarios) {
		this.funcionarios = funcionarios;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((idCargo == null) ? 0 : idCargo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Cargo other = (Cargo) obj;
		if (idCargo == null) {
			if (other.idCargo != null)
				return false;
		} else if (!idCargo.equals(other.idCargo))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		
		return this.idCargo + ";" + this.cargo;
	}
}
